
// System headers
#include "stm32f10x.h"

// My headers
#include "main.h"
#include "led.h"
#include "button.h"
#include "kl_lib.h"
#include "adc.h"


int main(void) {
    GeneralInit();
    LEDG_ON();

    uint32_t Tmr;
    bool a,b,c,y;
    while (1) {
//        Btn.Task();
        if (Delay.Elapsed(&Tmr, 150)) {
            a = (BTN1_IS_PRESSED())? true: false;
            b = (BTN2_IS_PRESSED())? true: false;
            c = (BTN3_IS_PRESSED())? true: false;
        }
        y = ((!a && !b && !c) || (!a && !b && c ) || (!a && b && c) || (a && b && c));
        if (y) LEDB_ON();
        else LEDB_OFF();


        CmdUnit.Task();         // Uart cmds
//        Adc.Task();
    }
}

void GeneralInit(void) {
    // Setup system clock
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
    SystemCoreClockUpdate();
    // Delay Setup
    Delay.Init();
    Delay.ms(9);

    CmdUnit.Init();

    Led.Init();
    Btn.Init();

//    Adc.Init();

    CmdUnit.Printf("\rCalelesta\r");
}

void CmdUnit_t::NewCmdHandler() {

}
